* Add 'deletedhistory' permission key for ability to view deleted history
[lhc/web/wiklou.git] / includes / Skin.php
1 <?php
2
3 /**
4 *
5 * @package MediaWiki
6 * @subpackage Skins
7 */
8
9 /**
10 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
11 */
12 if( defined( "MEDIAWIKI" ) ) {
13
14 # See skin.txt
15 require_once( 'Linker.php' );
16 require_once( 'Image.php' );
17
18 # Get a list of all skins available in /skins/
19 # Build using the regular expression '^(.*).php$'
20 # Array keys are all lower case, array value keep the case used by filename
21 #
22
23 $skinDir = dir($IP.'/skins');
24
25 # while code from www.php.net
26 while (false !== ($file = $skinDir->read())) {
27 if(preg_match('/^([^.].*)\.php$/',$file, $matches)) {
28 $aSkin = $matches[1];
29 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
30 }
31 }
32 $skinDir->close();
33 unset($matches);
34
35 require_once( 'RecentChange.php' );
36
37 /**
38 * @todo document
39 * @package MediaWiki
40 */
41 class RCCacheEntry extends RecentChange
42 {
43 var $secureName, $link;
44 var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
45 var $userlink, $timestamp, $watched;
46
47 function newFromParent( $rc )
48 {
49 $rc2 = new RCCacheEntry;
50 $rc2->mAttribs = $rc->mAttribs;
51 $rc2->mExtra = $rc->mExtra;
52 return $rc2;
53 }
54 } ;
55
56
57 /**
58 * The main skin class that provide methods and properties for all other skins
59 * including PHPTal skins.
60 * This base class is also the "Standard" skin.
61 * @package MediaWiki
62 */
63 class Skin extends Linker {
64 /**#@+
65 * @access private
66 */
67 var $lastdate, $lastline;
68 var $rc_cache ; # Cache for Enhanced Recent Changes
69 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
70 var $rcMoveIndex;
71 /**#@-*/
72
73 /** Constructor, call parent constructor */
74 function Skin() { parent::Linker(); }
75
76 /**
77 * Fetch the set of available skins.
78 * @return array of strings
79 * @static
80 */
81 function getSkinNames() {
82 global $wgValidSkinNames;
83 return $wgValidSkinNames;
84 }
85
86 /**
87 * Normalize a skin preference value to a form that can be loaded.
88 * If a skin can't be found, it will fall back to the configured
89 * default (or the old 'Classic' skin if that's broken).
90 * @param string $key
91 * @return string
92 * @static
93 */
94 function normalizeKey( $key ) {
95 global $wgDefaultSkin;
96 $skinNames = Skin::getSkinNames();
97
98 if( $key == '' ) {
99 // Don't return the default immediately;
100 // in a misconfiguration we need to fall back.
101 $key = $wgDefaultSkin;
102 }
103
104 if( isset( $skinNames[$key] ) ) {
105 return $key;
106 }
107
108 // Older versions of the software used a numeric setting
109 // in the user preferences.
110 $fallback = array(
111 0 => $wgDefaultSkin,
112 1 => 'nostalgia',
113 2 => 'cologneblue' );
114
115 if( isset( $fallback[$key] ) ){
116 $key = $fallback[$key];
117 }
118
119 if( isset( $skinNames[$key] ) ) {
120 return $key;
121 } else {
122 // The old built-in skin
123 return 'standard';
124 }
125 }
126
127 /**
128 * Factory method for loading a skin of a given type
129 * @param string $key 'monobook', 'standard', etc
130 * @return Skin
131 * @static
132 */
133 function &newFromKey( $key ) {
134 $key = Skin::normalizeKey( $key );
135
136 $skinNames = Skin::getSkinNames();
137 $skinName = $skinNames[$key];
138
139 global $IP;
140
141 # Grab the skin class and initialise it. Each skin checks for PHPTal
142 # and will not load if it's not enabled.
143 require_once( $IP.'/skins/'.$skinName.'.php' );
144
145 # Check if we got if not failback to default skin
146 $className = 'Skin'.$skinName;
147 if( !class_exists( $className ) ) {
148 # DO NOT die if the class isn't found. This breaks maintenance
149 # scripts and can cause a user account to be unrecoverable
150 # except by SQL manipulation if a previously valid skin name
151 # is no longer valid.
152 $className = 'SkinStandard';
153 require_once( $IP.'/skins/Standard.php' );
154 }
155 $skin =& new $className;
156 return $skin;
157 }
158
159 /** @return string path to the skin stylesheet */
160 function getStylesheet() {
161 return 'common/wikistandard.css?1';
162 }
163
164 /** @return string skin name */
165 function getSkinName() {
166 return 'standard';
167 }
168
169 function qbSetting() {
170 global $wgOut, $wgUser;
171
172 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
173 $q = $wgUser->getOption( 'quickbar' );
174 if ( '' == $q ) { $q = 0; }
175 return $q;
176 }
177
178 function initPage( &$out ) {
179 $fname = 'Skin::initPage';
180 wfProfileIn( $fname );
181
182 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => '/favicon.ico' ) );
183
184 $this->addMetadataLinks($out);
185
186 $this->mRevisionId = $out->mRevisionId;
187
188 wfProfileOut( $fname );
189 }
190
191 function addMetadataLinks( &$out ) {
192 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
193 global $wgRightsPage, $wgRightsUrl;
194
195 if( $out->isArticleRelated() ) {
196 # note: buggy CC software only reads first "meta" link
197 if( $wgEnableCreativeCommonsRdf ) {
198 $out->addMetadataLink( array(
199 'title' => 'Creative Commons',
200 'type' => 'application/rdf+xml',
201 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
202 }
203 if( $wgEnableDublinCoreRdf ) {
204 $out->addMetadataLink( array(
205 'title' => 'Dublin Core',
206 'type' => 'application/rdf+xml',
207 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
208 }
209 }
210 $copyright = '';
211 if( $wgRightsPage ) {
212 $copy = Title::newFromText( $wgRightsPage );
213 if( $copy ) {
214 $copyright = $copy->getLocalURL();
215 }
216 }
217 if( !$copyright && $wgRightsUrl ) {
218 $copyright = $wgRightsUrl;
219 }
220 if( $copyright ) {
221 $out->addLink( array(
222 'rel' => 'copyright',
223 'href' => $copyright ) );
224 }
225 }
226
227 function outputPage( &$out ) {
228 global $wgDebugComments;
229
230 wfProfileIn( 'Skin::outputPage' );
231 $this->initPage( $out );
232
233 $out->out( $out->headElement() );
234
235 $out->out( "\n<body" );
236 $ops = $this->getBodyOptions();
237 foreach ( $ops as $name => $val ) {
238 $out->out( " $name='$val'" );
239 }
240 $out->out( ">\n" );
241 if ( $wgDebugComments ) {
242 $out->out( "<!-- Wiki debugging output:\n" .
243 $out->mDebugtext . "-->\n" );
244 }
245
246 $out->out( $this->beforeContent() );
247
248 $out->out( $out->mBodytext . "\n" );
249
250 $out->out( $this->afterContent() );
251
252 wfProfileClose();
253 $out->out( $out->reportTime() );
254
255 $out->out( "\n</body></html>" );
256 }
257
258 function getHeadScripts() {
259 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
260 $r = "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
261 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
262 $userpage = $wgUser->getUserPage();
263 $userjs = htmlspecialchars( $this->makeUrl(
264 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
265 'action=raw&ctype='.$wgJsMimeType));
266 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
267 }
268 return $r;
269 }
270
271 /**
272 * To make it harder for someone to slip a user a fake
273 * user-JavaScript or user-CSS preview, a random token
274 * is associated with the login session. If it's not
275 * passed back with the preview request, we won't render
276 * the code.
277 *
278 * @param string $action
279 * @return bool
280 * @access private
281 */
282 function userCanPreview( $action ) {
283 global $wgTitle, $wgRequest, $wgUser;
284
285 if( $action != 'submit' )
286 return false;
287 if( !$wgRequest->wasPosted() )
288 return false;
289 if( !$wgTitle->userCanEditCssJsSubpage() )
290 return false;
291 return $wgUser->matchEditToken(
292 $wgRequest->getVal( 'wpEditToken' ) );
293 }
294
295 # get the user/site-specific stylesheet, SkinPHPTal called from RawPage.php (settings are cached that way)
296 function getUserStylesheet() {
297 global $wgOut, $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage;
298 $sheet = $this->getStylesheet();
299 $action = $wgRequest->getText('action');
300 $s = "@import \"$wgStylePath/$sheet\";\n";
301 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
302
303 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
304 $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
305 '@import "'.$this->makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
306
307 $s .= $this->doGetUserStyles();
308 return $s."\n";
309 }
310
311 /**
312 * placeholder, returns generated js in monobook
313 */
314 function getUserJs() { return; }
315
316 /**
317 * Return html code that include User stylesheets
318 */
319 function getUserStyles() {
320 global $wgOut, $wgStylePath;
321 $s = "<style type='text/css'>\n";
322 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
323 $s .= $this->getUserStylesheet();
324 $s .= "/*]]>*/ /* */\n";
325 $s .= "</style>\n";
326 return $s;
327 }
328
329 /**
330 * Some styles that are set by user through the user settings interface.
331 */
332 function doGetUserStyles() {
333 global $wgUser, $wgContLang, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
334
335 $s = '';
336
337 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
338 if($wgTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
339 $s .= $wgRequest->getText('wpTextbox1');
340 } else {
341 $userpage = $wgUser->getUserPage();
342 $s.= '@import "'.$this->makeUrl(
343 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
344 'action=raw&ctype=text/css').'";'."\n";
345 }
346 }
347
348 return $s . $this->reallyDoGetUserStyles();
349 }
350
351 function reallyDoGetUserStyles() {
352 global $wgUser;
353 $s = '';
354 if (($undopt = $wgUser->getOption("underline")) != 2) {
355 $underline = $undopt ? 'underline' : 'none';
356 $s .= "a { text-decoration: $underline; }\n";
357 }
358 if( $wgUser->getOption( 'highlightbroken' ) ) {
359 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
360 } else {
361 $s .= <<<END
362 a.new, #quickbar a.new,
363 a.stub, #quickbar a.stub {
364 color: inherit;
365 text-decoration: inherit;
366 }
367 a.new:after, #quickbar a.new:after {
368 content: "?";
369 color: #CC2200;
370 text-decoration: $underline;
371 }
372 a.stub:after, #quickbar a.stub:after {
373 content: "!";
374 color: #772233;
375 text-decoration: $underline;
376 }
377 END;
378 }
379 if( $wgUser->getOption( 'justify' ) ) {
380 $s .= "#article, #bodyContent { text-align: justify; }\n";
381 }
382 if( !$wgUser->getOption( 'showtoc' ) ) {
383 $s .= "#toc { display: none; }\n";
384 }
385 if( !$wgUser->getOption( 'editsection' ) ) {
386 $s .= ".editsection { display: none; }\n";
387 }
388 return $s;
389 }
390
391 function getBodyOptions() {
392 global $wgUser, $wgTitle, $wgOut, $wgRequest;
393
394 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
395
396 if ( 0 != $wgTitle->getNamespace() ) {
397 $a = array( 'bgcolor' => '#ffffec' );
398 }
399 else $a = array( 'bgcolor' => '#FFFFFF' );
400 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
401 $wgTitle->userCanEdit() ) {
402 $t = wfMsg( 'editthispage' );
403 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
404 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
405 $a += array ('ondblclick' => $s);
406
407 }
408 $a['onload'] = $wgOut->getOnloadHandler();
409 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
410 if( $a['onload'] != '' ) {
411 $a['onload'] .= ';';
412 }
413 $a['onload'] .= 'setupRightClickEdit()';
414 }
415 return $a;
416 }
417
418 /**
419 * URL to the logo
420 */
421 function getLogo() {
422 global $wgLogo;
423 return $wgLogo;
424 }
425
426 /**
427 * This will be called immediately after the <body> tag. Split into
428 * two functions to make it easier to subclass.
429 */
430 function beforeContent() {
431 return $this->doBeforeContent();
432 }
433
434 function doBeforeContent() {
435 global $wgOut, $wgTitle, $wgContLang;
436 $fname = 'Skin::doBeforeContent';
437 wfProfileIn( $fname );
438
439 $s = '';
440 $qb = $this->qbSetting();
441
442 if( $langlinks = $this->otherLanguages() ) {
443 $rows = 2;
444 $borderhack = '';
445 } else {
446 $rows = 1;
447 $langlinks = false;
448 $borderhack = 'class="top"';
449 }
450
451 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
452 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
453
454 $shove = ($qb != 0);
455 $left = ($qb == 1 || $qb == 3);
456 if($wgContLang->isRTL()) $left = !$left;
457
458 if ( !$shove ) {
459 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
460 $this->logoText() . '</td>';
461 } elseif( $left ) {
462 $s .= $this->getQuickbarCompensator( $rows );
463 }
464 $l = $wgContLang->isRTL() ? 'right' : 'left';
465 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
466
467 $s .= $this->topLinks() ;
468 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
469
470 $r = $wgContLang->isRTL() ? "left" : "right";
471 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
472 $s .= $this->nameAndLogin();
473 $s .= "\n<br />" . $this->searchForm() . "</td>";
474
475 if ( $langlinks ) {
476 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
477 }
478
479 if ( $shove && !$left ) { # Right
480 $s .= $this->getQuickbarCompensator( $rows );
481 }
482 $s .= "</tr>\n</table>\n</div>\n";
483 $s .= "\n<div id='article'>\n";
484
485 $notice = wfGetSiteNotice();
486 if( $notice ) {
487 $s .= "\n<div id='siteNotice'>$notice</div>\n";
488 }
489 $s .= $this->pageTitle();
490 $s .= $this->pageSubtitle() ;
491 $s .= $this->getCategories();
492 wfProfileOut( $fname );
493 return $s;
494 }
495
496
497 function getCategoryLinks () {
498 global $wgOut, $wgTitle, $wgUseCategoryMagic, $wgUseCategoryBrowser;
499 global $wgContLang;
500
501 if( !$wgUseCategoryMagic ) return '' ;
502 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
503
504 // Use Unicode bidi embedding override characters,
505 // to make sure links don't smash each other up in ugly ways.
506 $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
507 $embed = "<span dir='$dir'>";
508 $pop = '</span>';
509 $t = $embed . implode ( "$pop | $embed" , $wgOut->mCategoryLinks ) . $pop;
510
511 $msg = count( $wgOut->mCategoryLinks ) === 1 ? 'categories1' : 'categories';
512 $s = $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Categories' ),
513 wfMsg( $msg ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
514 . ': ' . $t;
515
516 # optional 'dmoz-like' category browser. Will be shown under the list
517 # of categories an article belong to
518 if($wgUseCategoryBrowser) {
519 $s .= '<br /><hr />';
520
521 # get a big array of the parents tree
522 $parenttree = $wgTitle->getParentCategoryTree();
523 # Skin object passed by reference cause it can not be
524 # accessed under the method subfunction drawCategoryBrowser
525 $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
526 # Clean out bogus first entry and sort them
527 unset($tempout[0]);
528 asort($tempout);
529 # Output one per line
530 $s .= implode("<br />\n", $tempout);
531 }
532
533 return $s;
534 }
535
536 /** Render the array as a serie of links.
537 * @param array $tree Categories tree returned by Title::getParentCategoryTree
538 * @param object &skin Skin passed by reference
539 * @return string separated by &gt;, terminate with "\n"
540 */
541 function drawCategoryBrowser($tree, &$skin) {
542 $return = '';
543 foreach ($tree as $element => $parent) {
544 if (empty($parent)) {
545 # element start a new list
546 $return .= "\n";
547 } else {
548 # grab the others elements
549 $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
550 }
551 # add our current element to the list
552 $eltitle = Title::NewFromText($element);
553 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
554 }
555 return $return;
556 }
557
558 function getCategories() {
559 $catlinks=$this->getCategoryLinks();
560 if(!empty($catlinks)) {
561 return "<p class='catlinks'>{$catlinks}</p>";
562 }
563 }
564
565 function getQuickbarCompensator( $rows = 1 ) {
566 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
567 }
568
569 /**
570 * This gets called immediately before the </body> tag.
571 * @return string HTML to be put after </body> ???
572 */
573 function afterContent() {
574 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
575 return $printfooter . $this->doAfterContent();
576 }
577
578 /** @return string Retrievied from HTML text */
579 function printSource() {
580 global $wgTitle;
581 $url = htmlspecialchars( $wgTitle->getFullURL() );
582 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
583 }
584
585 function printFooter() {
586 return "<p>" . $this->printSource() .
587 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
588 }
589
590 /** overloaded by derived classes */
591 function doAfterContent() { }
592
593 function pageTitleLinks() {
594 global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgRequest;
595
596 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
597 $action = $wgRequest->getText( 'action' );
598
599 $s = $this->printableLink();
600 $disclaimer = $this->disclaimerLink(); # may be empty
601 if( $disclaimer ) {
602 $s .= ' | ' . $disclaimer;
603 }
604 $privacy = $this->privacyLink(); # may be empty too
605 if( $privacy ) {
606 $s .= ' | ' . $privacy;
607 }
608
609 if ( $wgOut->isArticleRelated() ) {
610 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
611 $name = $wgTitle->getDBkey();
612 $image = new Image( $wgTitle );
613 if( $image->exists() ) {
614 $link = htmlspecialchars( $image->getURL() );
615 $style = $this->getInternalLinkAttributes( $link, $name );
616 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
617 }
618 }
619 }
620 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
621 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
622 wfMsg( 'currentrev' ) );
623 }
624
625 if ( $wgUser->getNewtalk() ) {
626 # do not show "You have new messages" text when we are viewing our
627 # own talk page
628 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
629 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ) );
630 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ) );
631 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
632 # disable caching
633 $wgOut->setSquidMaxage(0);
634 $wgOut->enableClientCache(false);
635 }
636 }
637
638 $undelete = $this->getUndeleteLink();
639 if( !empty( $undelete ) ) {
640 $s .= ' | '.$undelete;
641 }
642 return $s;
643 }
644
645 function getUndeleteLink() {
646 global $wgUser, $wgTitle, $wgContLang, $action;
647 if( $wgUser->isAllowed( 'deletedhistory' ) &&
648 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
649 ($n = $wgTitle->isDeleted() ) )
650 {
651 if ( $wgUser->isAllowed( 'delete' ) ) {
652 $msg = 'thisisdeleted';
653 } else {
654 $msg = 'viewdeleted';
655 }
656 return wfMsg( $msg,
657 $this->makeKnownLink(
658 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
659 wfMsg( 'restorelink' . ($n == 1 ? '1' : ''), $n ) ) );
660 }
661 return '';
662 }
663
664 function printableLink() {
665 global $wgOut, $wgFeedClasses, $wgRequest;
666
667 $baseurl = $_SERVER['REQUEST_URI'];
668 if( strpos( '?', $baseurl ) == false ) {
669 $baseurl .= '?';
670 } else {
671 $baseurl .= '&';
672 }
673 $baseurl = htmlspecialchars( $baseurl );
674 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
675
676 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
677 if( $wgOut->isSyndicated() ) {
678 foreach( $wgFeedClasses as $format => $class ) {
679 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
680 $s .= " | <a href=\"$feedurl\">{$format}</a>";
681 }
682 }
683 return $s;
684 }
685
686 function pageTitle() {
687 global $wgOut, $wgTitle, $wgUser;
688
689 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
690 return $s;
691 }
692
693 function pageSubtitle() {
694 global $wgOut;
695
696 $sub = $wgOut->getSubtitle();
697 if ( '' == $sub ) {
698 global $wgExtraSubtitle;
699 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
700 }
701 $subpages = $this->subPageSubtitle();
702 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
703 $s = "<p class='subtitle'>{$sub}</p>\n";
704 return $s;
705 }
706
707 function subPageSubtitle() {
708 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
709 $subpages = '';
710 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
711 $ptext=$wgTitle->getPrefixedText();
712 if(preg_match('/\//',$ptext)) {
713 $links = explode('/',$ptext);
714 $c = 0;
715 $growinglink = '';
716 foreach($links as $link) {
717 $c++;
718 if ($c<count($links)) {
719 $growinglink .= $link;
720 $getlink = $this->makeLink( $growinglink, $link );
721 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
722 if ($c>1) {
723 $subpages .= ' | ';
724 } else {
725 $subpages .= '&lt; ';
726 }
727 $subpages .= $getlink;
728 $growinglink .= '/';
729 }
730 }
731 }
732 }
733 return $subpages;
734 }
735
736 function nameAndLogin() {
737 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
738
739 $li = $wgContLang->specialPage( 'Userlogin' );
740 $lo = $wgContLang->specialPage( 'Userlogout' );
741
742 $s = '';
743 if ( $wgUser->isAnon() ) {
744 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
745 $n = wfGetIP();
746
747 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
748 $wgLang->getNsText( NS_TALK ) );
749
750 $s .= $n . ' ('.$tl.')';
751 } else {
752 $s .= wfMsg('notloggedin');
753 }
754
755 $rt = $wgTitle->getPrefixedURL();
756 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
757 $q = '';
758 } else { $q = "returnto={$rt}"; }
759
760 $s .= "\n<br />" . $this->makeKnownLinkObj(
761 Title::makeTitle( NS_SPECIAL, 'Userlogin' ),
762 wfMsg( 'login' ), $q );
763 } else {
764 $n = $wgUser->getName();
765 $rt = $wgTitle->getPrefixedURL();
766 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
767 $wgLang->getNsText( NS_TALK ) );
768
769 $tl = " ({$tl})";
770
771 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
772 $n ) . "{$tl}<br />" .
773 $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Userlogout' ), wfMsg( 'logout' ),
774 "returnto={$rt}" ) . ' | ' .
775 $this->specialLink( 'preferences' );
776 }
777 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
778 wfMsg( 'help' ) );
779
780 return $s;
781 }
782
783 function getSearchLink() {
784 $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
785 return $searchPage->getLocalURL();
786 }
787
788 function escapeSearchLink() {
789 return htmlspecialchars( $this->getSearchLink() );
790 }
791
792 function searchForm() {
793 global $wgRequest;
794 $search = $wgRequest->getText( 'search' );
795
796 $s = '<form name="search" class="inline" method="post" action="'
797 . $this->escapeSearchLink() . "\">\n"
798 . '<input type="text" name="search" size="19" value="'
799 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
800 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
801 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
802
803 return $s;
804 }
805
806 function topLinks() {
807 global $wgOut;
808 $sep = " |\n";
809
810 $s = $this->mainPageLink() . $sep
811 . $this->specialLink( 'recentchanges' );
812
813 if ( $wgOut->isArticleRelated() ) {
814 $s .= $sep . $this->editThisPage()
815 . $sep . $this->historyLink();
816 }
817 # Many people don't like this dropdown box
818 #$s .= $sep . $this->specialPagesList();
819
820 /* show links to different language variants */
821 global $wgDisableLangConversion, $wgContLang, $wgTitle;
822 $variants = $wgContLang->getVariants();
823 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
824 foreach( $variants as $code ) {
825 $varname = $wgContLang->getVariantname( $code );
826 if( $varname == 'disable' )
827 continue;
828 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
829 }
830 }
831
832 return $s;
833 }
834
835 function bottomLinks() {
836 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
837 $sep = " |\n";
838
839 $s = '';
840 if ( $wgOut->isArticleRelated() ) {
841 $s .= '<strong>' . $this->editThisPage() . '</strong>';
842 if ( $wgUser->isLoggedIn() ) {
843 $s .= $sep . $this->watchThisPage();
844 }
845 $s .= $sep . $this->talkLink()
846 . $sep . $this->historyLink()
847 . $sep . $this->whatLinksHere()
848 . $sep . $this->watchPageLinksLink();
849
850 if ($wgUseTrackbacks)
851 $s .= $sep . $this->trackbackLink();
852
853 if ( $wgTitle->getNamespace() == NS_USER
854 || $wgTitle->getNamespace() == NS_USER_TALK )
855
856 {
857 $id=User::idFromName($wgTitle->getText());
858 $ip=User::isIP($wgTitle->getText());
859
860 if($id || $ip) { # both anons and non-anons have contri list
861 $s .= $sep . $this->userContribsLink();
862 }
863 if( $this->showEmailUser( $id ) ) {
864 $s .= $sep . $this->emailUserLink();
865 }
866 }
867 if ( $wgTitle->getArticleId() ) {
868 $s .= "\n<br />";
869 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
870 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
871 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
872 }
873 $s .= "<br />\n" . $this->otherLanguages();
874 }
875 return $s;
876 }
877
878 function pageStats() {
879 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
880 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
881
882 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
883 if ( ! $wgOut->isArticle() ) { return ''; }
884 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
885 if ( 0 == $wgArticle->getID() ) { return ''; }
886
887 $s = '';
888 if ( !$wgDisableCounters ) {
889 $count = $wgLang->formatNum( $wgArticle->getCount() );
890 if ( $count ) {
891 $s = wfMsg( 'viewcount', $count );
892 }
893 }
894
895 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
896 require_once('Credits.php');
897 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
898 } else {
899 $s .= $this->lastModified();
900 }
901
902 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
903 $dbr =& wfGetDB( DB_SLAVE );
904 extract( $dbr->tableNames( 'watchlist' ) );
905 $sql = "SELECT COUNT(*) AS n FROM $watchlist
906 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
907 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
908 $res = $dbr->query( $sql, 'Skin::pageStats');
909 $x = $dbr->fetchObject( $res );
910 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
911 }
912
913 return $s . ' ' . $this->getCopyright();
914 }
915
916 function getCopyright() {
917 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
918
919
920 $oldid = $wgRequest->getVal( 'oldid' );
921 $diff = $wgRequest->getVal( 'diff' );
922
923 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
924 $msg = 'history_copyright';
925 } else {
926 $msg = 'copyright';
927 }
928
929 $out = '';
930 if( $wgRightsPage ) {
931 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
932 } elseif( $wgRightsUrl ) {
933 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
934 } else {
935 # Give up now
936 return $out;
937 }
938 $out .= wfMsgForContent( $msg, $link );
939 return $out;
940 }
941
942 function getCopyrightIcon() {
943 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
944 $out = '';
945 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
946 $out = $wgCopyrightIcon;
947 } else if ( $wgRightsIcon ) {
948 $icon = htmlspecialchars( $wgRightsIcon );
949 if ( $wgRightsUrl ) {
950 $url = htmlspecialchars( $wgRightsUrl );
951 $out .= '<a href="'.$url.'">';
952 }
953 $text = htmlspecialchars( $wgRightsText );
954 $out .= "<img src=\"$icon\" alt='$text' />";
955 if ( $wgRightsUrl ) {
956 $out .= '</a>';
957 }
958 }
959 return $out;
960 }
961
962 function getPoweredBy() {
963 global $wgStylePath;
964 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
965 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
966 return $img;
967 }
968
969 function lastModified() {
970 global $wgLang, $wgArticle, $wgLoadBalancer;
971
972 $timestamp = $wgArticle->getTimestamp();
973 if ( $timestamp ) {
974 $d = $wgLang->timeanddate( $timestamp, true );
975 $s = ' ' . wfMsg( 'lastmodified', $d );
976 } else {
977 $s = '';
978 }
979 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
980 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
981 }
982 return $s;
983 }
984
985 function logoText( $align = '' ) {
986 if ( '' != $align ) { $a = " align='{$align}'"; }
987 else { $a = ''; }
988
989 $mp = wfMsg( 'mainpage' );
990 $titleObj = Title::newFromText( $mp );
991 if ( is_object( $titleObj ) ) {
992 $url = $titleObj->escapeLocalURL();
993 } else {
994 $url = '';
995 }
996
997 $logourl = $this->getLogo();
998 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
999 return $s;
1000 }
1001
1002 /**
1003 * show a drop-down box of special pages
1004 * @TODO crash bug913. Need to be rewrote completly.
1005 */
1006 function specialPagesList() {
1007 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
1008 require_once('SpecialPage.php');
1009 $a = array();
1010 $pages = SpecialPage::getPages();
1011
1012 // special pages without access restriction
1013 foreach ( $pages[''] as $name => $page ) {
1014 $a[$name] = $page->getDescription();
1015 }
1016
1017 // Other special pages that are restricted.
1018 // Copied from SpecialSpecialpages.php
1019 foreach($wgAvailableRights as $right) {
1020 if( $wgUser->isAllowed($right) ) {
1021 /** Add all pages for this right */
1022 if(isset($pages[$right])) {
1023 foreach($pages[$right] as $name => $page) {
1024 $a[$name] = $page->getDescription();
1025 }
1026 }
1027 }
1028 }
1029
1030 $go = wfMsg( 'go' );
1031 $sp = wfMsg( 'specialpages' );
1032 $spp = $wgContLang->specialPage( 'Specialpages' );
1033
1034 $s = '<form id="specialpages" method="get" class="inline" ' .
1035 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1036 $s .= "<select name=\"wpDropdown\">\n";
1037 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1038
1039
1040 foreach ( $a as $name => $desc ) {
1041 $p = $wgContLang->specialPage( $name );
1042 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1043 }
1044 $s .= "</select>\n";
1045 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1046 $s .= "</form>\n";
1047 return $s;
1048 }
1049
1050 function mainPageLink() {
1051 $mp = wfMsgForContent( 'mainpage' );
1052 $mptxt = wfMsg( 'mainpage');
1053 $s = $this->makeKnownLink( $mp, $mptxt );
1054 return $s;
1055 }
1056
1057 function copyrightLink() {
1058 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1059 wfMsg( 'copyrightpagename' ) );
1060 return $s;
1061 }
1062
1063 function privacyLink() {
1064 $privacy = wfMsg( 'privacy' );
1065 if ($privacy == '-') {
1066 return '';
1067 } else {
1068 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1069 }
1070 }
1071
1072 function aboutLink() {
1073 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1074 wfMsg( 'aboutsite' ) );
1075 return $s;
1076 }
1077
1078 function disclaimerLink() {
1079 $disclaimers = wfMsg( 'disclaimers' );
1080 if ($disclaimers == '-') {
1081 return '';
1082 } else {
1083 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1084 $disclaimers );
1085 }
1086 }
1087
1088 function editThisPage() {
1089 global $wgOut, $wgTitle, $wgRequest;
1090
1091 if ( ! $wgOut->isArticleRelated() ) {
1092 $s = wfMsg( 'protectedpage' );
1093 } else {
1094 if ( $wgTitle->userCanEdit() ) {
1095 $t = wfMsg( 'editthispage' );
1096 } else {
1097 $t = wfMsg( 'viewsource' );
1098 }
1099
1100 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1101 }
1102 return $s;
1103 }
1104
1105 /**
1106 * Return URL options for the 'edit page' link.
1107 * This may include an 'oldid' specifier, if the current page view is such.
1108 *
1109 * @return string
1110 * @access private
1111 */
1112 function editUrlOptions() {
1113 global $wgArticle;
1114
1115 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1116 return "action=edit&oldid=" . intval( $this->mRevisionId );
1117 } else {
1118 return "action=edit";
1119 }
1120 }
1121
1122 function deleteThisPage() {
1123 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1124
1125 $diff = $wgRequest->getVal( 'diff' );
1126 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1127 $t = wfMsg( 'deletethispage' );
1128
1129 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1130 } else {
1131 $s = '';
1132 }
1133 return $s;
1134 }
1135
1136 function protectThisPage() {
1137 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1138
1139 $diff = $wgRequest->getVal( 'diff' );
1140 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1141 if ( $wgTitle->isProtected() ) {
1142 $t = wfMsg( 'unprotectthispage' );
1143 $q = 'action=unprotect';
1144 } else {
1145 $t = wfMsg( 'protectthispage' );
1146 $q = 'action=protect';
1147 }
1148 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1149 } else {
1150 $s = '';
1151 }
1152 return $s;
1153 }
1154
1155 function watchThisPage() {
1156 global $wgUser, $wgOut, $wgTitle;
1157
1158 if ( $wgOut->isArticleRelated() ) {
1159 if ( $wgTitle->userIsWatching() ) {
1160 $t = wfMsg( 'unwatchthispage' );
1161 $q = 'action=unwatch';
1162 } else {
1163 $t = wfMsg( 'watchthispage' );
1164 $q = 'action=watch';
1165 }
1166 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1167 } else {
1168 $s = wfMsg( 'notanarticle' );
1169 }
1170 return $s;
1171 }
1172
1173 function moveThisPage() {
1174 global $wgTitle;
1175
1176 if ( $wgTitle->userCanMove() ) {
1177 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Movepage' ),
1178 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1179 } else {
1180 // no message if page is protected - would be redundant
1181 return '';
1182 }
1183 }
1184
1185 function historyLink() {
1186 global $wgTitle;
1187
1188 return $this->makeKnownLinkObj( $wgTitle,
1189 wfMsg( 'history' ), 'action=history' );
1190 }
1191
1192 function whatLinksHere() {
1193 global $wgTitle;
1194
1195 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' ),
1196 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1197 }
1198
1199 function userContribsLink() {
1200 global $wgTitle;
1201
1202 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ),
1203 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1204 }
1205
1206 function showEmailUser( $id ) {
1207 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1208 return $wgEnableEmail &&
1209 $wgEnableUserEmail &&
1210 $wgUser->isLoggedIn() && # show only to signed in users
1211 0 != $id; # we can only email to non-anons ..
1212 # '' != $id->getEmail() && # who must have an email address stored ..
1213 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1214 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1215 }
1216
1217 function emailUserLink() {
1218 global $wgTitle;
1219
1220 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Emailuser' ),
1221 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1222 }
1223
1224 function watchPageLinksLink() {
1225 global $wgOut, $wgTitle;
1226
1227 if ( ! $wgOut->isArticleRelated() ) {
1228 return '(' . wfMsg( 'notanarticle' ) . ')';
1229 } else {
1230 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL,
1231 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1232 'target=' . $wgTitle->getPrefixedURL() );
1233 }
1234 }
1235
1236 function trackbackLink() {
1237 global $wgTitle;
1238
1239 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1240 . wfMsg('trackbacklink') . "</a>";
1241 }
1242
1243 function otherLanguages() {
1244 global $wgOut, $wgContLang, $wgTitle, $wgHideInterlanguageLinks;
1245
1246 if ( $wgHideInterlanguageLinks ) {
1247 return '';
1248 }
1249
1250 $a = $wgOut->getLanguageLinks();
1251 if ( 0 == count( $a ) ) {
1252 return '';
1253 }
1254
1255 $s = wfMsg( 'otherlanguages' ) . ': ';
1256 $first = true;
1257 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1258 foreach( $a as $l ) {
1259 if ( ! $first ) { $s .= ' | '; }
1260 $first = false;
1261
1262 $nt = Title::newFromText( $l );
1263 $url = $nt->escapeFullURL();
1264 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1265
1266 if ( '' == $text ) { $text = $l; }
1267 $style = $this->getExternalLinkAttributes( $l, $text );
1268 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1269 }
1270 if($wgContLang->isRTL()) $s .= '</span>';
1271 return $s;
1272 }
1273
1274 function bugReportsLink() {
1275 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1276 wfMsg( 'bugreports' ) );
1277 return $s;
1278 }
1279
1280 function dateLink() {
1281 global $wgLinkCache;
1282 $t1 = Title::newFromText( gmdate( 'F j' ) );
1283 $t2 = Title::newFromText( gmdate( 'Y' ) );
1284
1285 $wgLinkCache->suspend();
1286 $id = $t1->getArticleID();
1287 $wgLinkCache->resume();
1288
1289 if ( 0 == $id ) {
1290 $s = $this->makeBrokenLink( $t1->getText() );
1291 } else {
1292 $s = $this->makeKnownLink( $t1->getText() );
1293 }
1294 $s .= ', ';
1295
1296 $wgLinkCache->suspend();
1297 $id = $t2->getArticleID();
1298 $wgLinkCache->resume();
1299
1300 if ( 0 == $id ) {
1301 $s .= $this->makeBrokenLink( $t2->getText() );
1302 } else {
1303 $s .= $this->makeKnownLink( $t2->getText() );
1304 }
1305 return $s;
1306 }
1307
1308 function talkLink() {
1309 global $wgTitle, $wgLinkCache;
1310
1311 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1312 # No discussion links for special pages
1313 return '';
1314 }
1315
1316 if( $wgTitle->isTalkPage() ) {
1317 $link = $wgTitle->getSubjectPage();
1318 switch( $link->getNamespace() ) {
1319 case NS_MAIN:
1320 $text = wfMsg('articlepage');
1321 break;
1322 case NS_USER:
1323 $text = wfMsg('userpage');
1324 break;
1325 case NS_PROJECT:
1326 $text = wfMsg('wikipediapage');
1327 break;
1328 case NS_IMAGE:
1329 $text = wfMsg('imagepage');
1330 break;
1331 default:
1332 $text= wfMsg('articlepage');
1333 }
1334 } else {
1335 $link = $wgTitle->getTalkPage();
1336 $text = wfMsg( 'talkpage' );
1337 }
1338
1339 $wgLinkCache->suspend();
1340 $s = $this->makeLinkObj( $link, $text );
1341 $wgLinkCache->resume();
1342
1343 return $s;
1344 }
1345
1346 function commentLink() {
1347 global $wgContLang, $wgTitle, $wgLinkCache;
1348
1349 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1350 return '';
1351 }
1352 return $this->makeKnownLinkObj( $wgTitle->getTalkPage(),
1353 wfMsg( 'postcomment' ), 'action=edit&section=new' );
1354 }
1355
1356 /* these are used extensively in SkinPHPTal, but also some other places */
1357 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1358 $title = Title::makeTitle( NS_SPECIAL, $name );
1359 return $title->getLocalURL( $urlaction );
1360 }
1361
1362 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1363 $title = Title::newFromText( wfMsgForContent($name) );
1364 $this->checkTitle($title, $name);
1365 return $title->getLocalURL( $urlaction );
1366 }
1367
1368 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1369 $title = Title::newFromText( $name );
1370 $this->checkTitle($title, $name);
1371 return $title->getLocalURL( $urlaction );
1372 }
1373
1374 # If url string starts with http, consider as external URL, else
1375 # internal
1376 /*static*/ function makeInternalOrExternalUrl( $name ) {
1377 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1378 return $name;
1379 } else {
1380 return $this->makeUrl( $name );
1381 }
1382 }
1383
1384 # this can be passed the NS number as defined in Language.php
1385 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN ) {
1386 $title = Title::makeTitleSafe( $namespace, $name );
1387 $this->checkTitle($title, $name);
1388 return $title->getLocalURL( $urlaction );
1389 }
1390
1391 /* these return an array with the 'href' and boolean 'exists' */
1392 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1393 $title = Title::newFromText( $name );
1394 $this->checkTitle($title, $name);
1395 return array(
1396 'href' => $title->getLocalURL( $urlaction ),
1397 'exists' => $title->getArticleID() != 0?true:false
1398 );
1399 }
1400
1401 /**
1402 * Make URL details where the article exists (or at least it's convenient to think so)
1403 */
1404 function makeKnownUrlDetails( $name, $urlaction='' ) {
1405 $title = Title::newFromText( $name );
1406 $this->checkTitle($title, $name);
1407 return array(
1408 'href' => $title->getLocalURL( $urlaction ),
1409 'exists' => true
1410 );
1411 }
1412
1413 # make sure we have some title to operate on
1414 /*static*/ function checkTitle ( &$title, &$name ) {
1415 if(!is_object($title)) {
1416 $title = Title::newFromText( $name );
1417 if(!is_object($title)) {
1418 $title = Title::newFromText( '--error: link target missing--' );
1419 }
1420 }
1421 }
1422
1423 /**
1424 * Build an array that represents the sidebar(s), the navigation bar among them
1425 *
1426 * @return array
1427 * @access private
1428 */
1429 function buildSidebar() {
1430 global $wgTitle, $action;
1431
1432 $fname = 'SkinTemplate::buildSidebar';
1433 $pageurl = $wgTitle->getLocalURL();
1434 wfProfileIn( $fname );
1435
1436 $bar = array();
1437 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1438 foreach ($lines as $line) {
1439 if (strpos($line, '*') !== 0)
1440 continue;
1441 if (strpos($line, '**') !== 0) {
1442 $line = trim($line, '* ');
1443 $heading = $line;
1444 } else {
1445 if (strpos($line, '|') !== false) { // sanity check
1446 $line = explode( '|' , trim($line, '* '), 2 );
1447 $link = wfMsgForContent( $line[0] );
1448 if ($link == '-')
1449 continue;
1450 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1451 $text = $line[1];
1452 if (wfEmptyMsg($line[0], $link))
1453 $link = $line[0];
1454 $href = $this->makeInternalOrExternalUrl( $link );
1455 $bar[$heading][] = array(
1456 'text' => $text,
1457 'href' => $href,
1458 'id' => 'n-' . strtr($line[1], ' ', '-'),
1459 'active' => $pageurl == $href
1460 );
1461 } else { continue; }
1462 }
1463 }
1464
1465 wfProfileOut( $fname );
1466 return $bar;
1467 }
1468 }
1469
1470 }
1471 ?>